import { LoginParams } from '@/pages/Login';
import { LoginResponse } from '@/types/data.d.';
import request from '@/utils/request';
import { changeToken, clearToken } from '../modules/login';
import { AppThunk } from './../index';

// 3. 异步action
// 3. 异步action
export const loginAction = (payload?: LoginParams): AppThunk => {
  return async (dispatch, getState) => {
    const res: LoginResponse = await request.post('/authorizations', payload)
    console.log(res)
    dispatch(changeToken(res.data))
  }
}
export const getCodeAction = (payload?: LoginParams): AppThunk => {
  return async (dispatch, getState) => {
    await request.get('/sms/codes/' + payload)
  }
}
export const logOutAction = (payload?: LoginParams): AppThunk => {
  return async (dispatch, getState) => {
    dispatch(clearToken())
  }
}


